//
//  MainTabBarViewController.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/8.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "MainTabBarViewController.h"
#import "UITabBar+CustomBadge.h"
#import "YLJTabBar.h"

#import "HomeViewController.h"
#import "MessageViewController.h"
#import "ShopCarViewController.h"
#import "MyViewController.h"

#import "CircleListViewController.h"
#import "FreeManagersViewController.h"

#import "GLGWBaesNavigationController.h"

#import "HomeMaiChongLayerView.h"

@interface MainTabBarViewController ()<YLJTabBarDelegate>
@property (nonatomic,strong) NSMutableArray * VCS;//tabbar root VC

@end

@implementation MainTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    YLJTabBar * tabbar = [YLJTabBar new];
    tabbar.myDelegate = self;
    [self setValue:tabbar forKey:@"tabBar"];
    //改变tabbar 线条颜色
    CGRect rect = CGRectMake(0, 0,KScreenWidth, 0.8);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context,
                                   [UIColor colorWithHexString:@"#EAEAEA"].CGColor);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.tabBar setShadowImage:img];
    [self.tabBar setBackgroundImage:[[UIImage alloc]init]];
    [self setUpAllChildViewController];
}

-(void)setUpAllChildViewController{
    _VCS = @[].mutableCopy;
    HomeViewController *HomeVC = [[HomeViewController alloc] init];
    [self setupChildViewController:HomeVC title:@"首页" imageName:@"icon_shouye" seleceImageName:@"icon_shouye_select"];
    //
    if (self.accountType == AccountType_FreeManagers) {
        CircleListViewController *circleListVC = [[CircleListViewController alloc] init];
        [self setupChildViewController:circleListVC title:@"圈子" imageName:@"icon_quanzi" seleceImageName:@"icon_quanziSelect"];
    }else{
        MessageViewController *messageVC = [[MessageViewController alloc] init];
        [self setupChildViewController:messageVC title:@"消息" imageName:@"icon_xinxi" seleceImageName:@"icon_xinxi_select"];
    }
    //
    if (self.accountType == AccountType_FreeManagers) {
        FreeManagersViewController *freeManageVC = [[FreeManagersViewController alloc] init];
        [self setupChildViewController:freeManageVC title:@"经理人" imageName:@"icon_jingliren" seleceImageName:@"icon_jinglirenSelect"];
    }else{
        ShopCarViewController *shopCarVC = [[ShopCarViewController alloc] init];
        [self setupChildViewController:shopCarVC title:@"购物车" imageName:@"icon_gouwuche" seleceImageName:@"icon_gouwuche_Select"];
    }
    //
    MyViewController *MarketVC = [[MyViewController alloc] init];
    [self setupChildViewController:MarketVC title:@"我的" imageName:@"icon_wode" seleceImageName:@"icon_wode_select"];
    self.viewControllers = _VCS;
}

-(void)setupChildViewController:(UIViewController*)controller title:(NSString *)title imageName:(NSString *)imageName seleceImageName:(NSString *)selectImageName{
    controller.title = title;
    controller.tabBarItem.title = title;//跟上面一样效果
    controller.tabBarItem.titlePositionAdjustment = UIOffsetMake(0,-2);
    controller.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    controller.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //未选中字体颜色
    [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"#999999"],NSFontAttributeName:[UIFont systemFontOfSize:10]} forState:UIControlStateNormal];
    //选中字体颜色
    [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:kColor_Rule_Yellow,NSFontAttributeName:[UIFont systemFontOfSize:10]} forState:UIControlStateSelected];
    //包装导航控制器
    GLGWBaesNavigationController *nav = [[GLGWBaesNavigationController alloc]initWithRootViewController:controller];
    [_VCS addObject:nav];
    
}

-(void)tabBarPlusBtnClick:(YLJTabBar *)tabBar{
    HomeMaiChongLayerView * yuyingView = [[HomeMaiChongLayerView alloc] initWithSayVoiceView];
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
